package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeWarning;
import com.ruoyi.grape.service.IGrapeWarningService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预警历史信息Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/warning")
public class GrapeWarningController extends BaseController
{
    @Autowired
    private IGrapeWarningService grapeWarningService;

    /**
     * 查询预警历史信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:warning:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeWarning grapeWarning)
    {
        startPage();
        List<GrapeWarning> list = grapeWarningService.selectGrapeWarningList(grapeWarning);
        return getDataTable(list);
    }

    /**
     * 导出预警历史信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:warning:export')")
    @Log(title = "预警历史信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeWarning grapeWarning)
    {
        List<GrapeWarning> list = grapeWarningService.selectGrapeWarningList(grapeWarning);
        ExcelUtil<GrapeWarning> util = new ExcelUtil<GrapeWarning>(GrapeWarning.class);
        util.exportExcel(response, list, "预警历史信息数据");
    }

    /**
     * 获取预警历史信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:warning:query')")
    @GetMapping(value = "/{warningId}")
    public AjaxResult getInfo(@PathVariable("warningId") Long warningId)
    {
        return success(grapeWarningService.selectGrapeWarningByWarningId(warningId));
    }

    /**
     * 新增预警历史信息
     */
    @PreAuthorize("@ss.hasPermi('grape:warning:add')")
    @Log(title = "预警历史信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeWarning grapeWarning)
    {
        return toAjax(grapeWarningService.insertGrapeWarning(grapeWarning));
    }

    /**
     * 修改预警历史信息
     */
    @PreAuthorize("@ss.hasPermi('grape:warning:edit')")
    @Log(title = "预警历史信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeWarning grapeWarning)
    {
        return toAjax(grapeWarningService.updateGrapeWarning(grapeWarning));
    }

    /**
     * 删除预警历史信息
     */
    @PreAuthorize("@ss.hasPermi('grape:warning:remove')")
    @Log(title = "预警历史信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warningIds}")
    public AjaxResult remove(@PathVariable Long[] warningIds)
    {
        return toAjax(grapeWarningService.deleteGrapeWarningByWarningIds(warningIds));
    }
}
